package main

import "fmt"

func main() {
	//new := deleteDuplicates(&ListNode{
	//	Val: 1,
	//	Next: &ListNode{
	//		Val: 2,
	//		Next: &ListNode{
	//			Val: 2,
	//			Next: &ListNode{
	//				Val: 3,
	//				Next: &ListNode{
	//					Val: 3,
	//				},
	//			},
	//		},
	//	}})
	new := deleteDuplicates(&ListNode{
		Val: 1,
		Next: &ListNode{
			Val: 1,
		}})
	for tmp := new; tmp != nil; tmp = tmp.Next {
		fmt.Print(" ", tmp.Val)
	}
}

type ListNode struct {
	Val  int
	Next *ListNode
}

func deleteDuplicates(head *ListNode) *ListNode {
	if head == nil {
		return nil
	}

	prev := head
	prev.Next = nil
	next := head.Next

	for next != nil {
		if next.Val == prev.Val {
			next = next.Next
		} else {
			prev.Next = next
			next = next.Next
			prev = prev.Next
			prev.Next = nil
		}
	}
	return head
}